package net.sxnic.workflow.whimpl;

import net.sxnic.workflow.context.WfContextImpl;
import net.sxnic.workflow.handler.AbstractHandler;
import net.sxnic.workflow.handler.HandlerExt;
import net.sxnic.workflow.handler.WfHandlerException;
import net.sxnic.workflow.wfentity.WfEntity;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EndCurrTaskHandler extends AbstractHandler<WfEntity> implements
		HandlerExt<WfEntity> {

	private static Logger logger = LoggerFactory
			.getLogger(EndCurrTaskHandler.class);

	public EndCurrTaskHandler(WfContextImpl<WfEntity> context) {
		super(context);
	}

	@Override
	public void editExecute() throws WfHandlerException {

	}

	@Override
	public void saveExecute() throws WfHandlerException {

	}

	@Override
	public void viewExecute() throws WfHandlerException {

	}

	@Override
	public void submitExecute() throws WfHandlerException {
		if (StringUtils.isBlank(context.getSelectedNextAssignees())) {
			context.getTask().setComments(context.getTaskComment());
			context.getTaskManager().endTask(context.getTask().getId());
			logger.debug("==invoker===submit===没有接收人，只结束当前任务，不再创建新任务=="
					+ context.getTask());
		} else {
			context.getTaskManager().endTask(context.getTask(),
					context.getSelectedNextAssignees(),
					context.getTaskComment());
			logger.debug("==invoker===submit===success==结束当前任务，并创建新任务=="
					+ context.getTask());
		}
	}

}
